import java.io.*;
import java.util.ArrayList;
import java.util.Arrays;

/**
 *  文件读写
 */
public class FileOperation {
     static void save(String content,String filename){
        BufferedWriter writer = null;
        try {
            writer = new BufferedWriter(new FileWriter(filename,true));
        } catch (IOException e) {
            e.printStackTrace();
        }
        try {
            writer.write(content);
            writer.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    static void  read(ArrayList<String> listType, String filename){
        BufferedReader reader = null;
        try {
            reader = new BufferedReader(new FileReader(filename));
            String str;
            while ((str = reader.readLine()) != null) {
                str = str.replaceAll("[^[0-9]\\+\\-\\=\\,]","");
                String[]  as = str.split(",");
                listType.addAll(Arrays.asList(as));
            }
        } catch (IOException e) {
            System.out.println("文件读取失败！文件不存在！");
        }
    }
    static void clearFile(String filename){
         BufferedWriter writer = null;
        try {
             writer = new BufferedWriter(new FileWriter(filename));
             writer.write("");
        } catch (IOException e) {
            System.out.println("文件清空失败！文件不存在！");
        }
    }
    static boolean isExist(String filename){
        File file = new File(filename);
        return file.exists();
    }
    // 判断题目文件是否存在
    static void willCreate(){
        loadingStatus loadingStatus = new loadingStatus();
        if (!isExist("MixBase.txt")){loadingStatus.setVisible(true);}
        Thread thread1 = new Thread(new myThread1());
        Thread thread2 = new Thread(new myThread2());
        thread1.start();
        thread2.start();
        BinaryOperationBase binaryOperationBase = new BinaryOperationBase();
        try {
            thread1.join();
            thread2.join();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        if (!isExist("MixBase.txt")){
            binaryOperationBase.getMixBase();
            loadingStatus.setVisible(false);
        }
    }
}
